package com.lagou.controller;

import java.util.Calendar;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;
import com.lagou.pojo.Article;
import com.lagou.service.ArticleService;

@Controller
public class LoginController {
	
	@Autowired
	private ArticleService articleService;

    @RequestMapping("/index.html")
    public String toLoginPage(@RequestParam(required=false,value="pageNum") Integer pageNum,Model model){

    	int pageSize =3;
    	if (pageNum==null) {
    		pageNum=1;
		}
        model.addAttribute("currentYear", Calendar.getInstance().get(Calendar.YEAR));
        PageInfo<Article> listArticle = articleService.listArticle(pageNum, pageSize);
        
        model.addAttribute("articles", listArticle.getList());
        model.addAttribute("firstPage", 1);
        model.addAttribute("lastPage", listArticle.getPages());
        model.addAttribute("pageNum", 1);
        if (null!=pageNum) {
        	model.addAttribute("pageNum", pageNum);
		}
        return "index";
    }


}
